<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $bbsdata=M('think_data');
        $data=$bbsdata->order("id desc")->select();
        $bbscount=$bbsdata->count();
        $this->assign('bbscount',$bbscount);
	$this->assign('row',$data);
     $this->display();
        }
    public function del(){
        $id=I('get.id',0);
        $bbsdata=M('think_data');
        $rs=$bbsdata->delete($id);
 if($rs){
    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
    $this->success('删除成功',U('home/index/index'),5);
} else {
    //错误页面的默认跳转页面是返回前一页，通常不需要设置
    $this->error('删除失败');
}
    }
     public function edit(){
         $id=I('get.id',0);
	    //实例化模型类
	    $model=M('think_data');
	    //获取该id的留言
        $data=$model->where("id=$id")->find();
        $this->assign("row",$data);
         $this->display();
      
     }
     public function update(){
         $id=I('get.id',0);
         $data['username']=I('post.username',' ');
         $data['sex']=I('post.sex','男 ');
         $data['message']=I('post.message',' ');
         $data['imgurl']=I('post.imgurl',' ');
         $data['m_date']=date('Y-m-d H:i:s',time());
         $data['username']=I('post.username',' ');
     }
     public function add(){
         $model = M("think_data");
         if($model->create()){
             $model->m_date=date('Y-m-d H:i:s',time());
             $result = $model->add();
         
         if($result){
             $this->
             success('留言成功',U('Home/Index/index'));
             
         }
 else {
     $this->error('留言失败');
 }
 
   }
     }
}